import { post, get } from '@/http/index'
import type { UserModel } from '@/type/User'
import { DeconstructionKvModel } from '@/utils/objUtils'

export async function login(user: string, password: string) {
  const tokenRes = await post<string>("user/GetToken", { user: user, password: password })
  const tokenStr = tokenRes.Data[0]
  return tokenStr
}


export async function getUser(pk: string) {
  return await get<UserModel>("user/Get", { pk: pk })
}

export async function listUser(cond: any) {
  return await post<UserModel>("user/List", cond)
}

export async function saveUser(data: UserModel) {
  DeconstructionKvModel(data)
  return await post<UserModel>("user/Save", data)
}

export async function changePassword(userId: string, password: string, validPassword: string) {
  const tokenRes = await post<string>("user/ChangePassword", { user: userId, password: password, validPassword: validPassword })
  const tokenStr = tokenRes.Data[0]
  return tokenStr
}
